<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑政策</title>
  </head>
  <body>
    <div id="policy_form" style="height:580px;" class="x-form-item">
    </div>
    <script>
        /*
         * Ext JS Library 2.1
         * Copyright(c) 2006-2008, Ext JS, LLC.
         * licensing@extjs.com
         *
         * http://extjs.com/license
         */
        Ext.onReady(function(){
            var policyForm;
            var airways = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getInternalAirways'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['id', 'airways_name'])
                }),
                name: 'airways',
                loadingText: '正在加载...',
                displayField: 'airways_name',
                valueField: 'id',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'airways_id',
                fieldLabel: "<span class='red'>*</span>航空公司",
                emptyText: '请选择...',
                editable: false,
                allowBlank: false,
                width: 130,
                maxHeight: 150,
                tabIndex: 4
            });
                
            var airportFrom = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllAirportComboBox'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['id', 'airport_name'])
                }),
                name: 'airport_from',
                loadingText: '正在加载...',
                displayField: 'airport_name',
                valueField: 'id',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'airport_from_id',
                fieldLabel: '<span class="red">*</span>始发城市',
                emptyText: '请选择...',
                editable: false,
                allowBlank: false,
                width: 130,
                maxHeight: 150,
                tabIndex: 4
            });
                                
            var flights = new Ext.form.TextField({
                fieldLabel: '适用航班',
                //allowBlank: false,
                name: 'flights',
                anchor: '90%'
            });
                
            var rakeOff = new Ext.form.NumberField({
                fieldLabel: '<span class="red">*</span>B政策折扣',
                allowBlank: false,
                name: 'rake_off',
                anchor: '90%'
            });
            //自动出票
            var single = new Ext.form.Radio({
                fieldLabel: '航程类型',
                name: 'trip_type',
                id: 'line_type_single',
                boxLabel: '单程',
                //checked: true,
                inputValue: '单程'
            });
            var twice = new Ext.form.Radio({
                fieldLabel: '往返',
                name: 'trip_type',
                id: 'line_type_twice',
                boxLabel: '往返',
                checked: false,
                hideLabel: true,
                inputValue: '往返'
            });
            var dateBegin = new Ext.form.DateField({
                fieldLabel: '<span class="red">*</span>开始日期',
                name: 'date_begin',
                id: 'date_begin',
                format: 'Y-m-d', //格式化日期   
                width: '80',
                //disabledDays: [0,6],	//不让选择周六，周日   
                //disabledDaysText: "周末要休息",   
                invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                anchor: '90%',
                vtype: 'daterange',
                endDateField: 'date_end'
            });
            
            var dateEnd = new Ext.form.DateField({
                fieldLabel: '<span class="red">*</span>结束日期',
                name: 'date_end',
                id: 'date_end',
                format: 'Y-m-d', //格式化日期   
                width: '80',
                //disabledDays: [0,6],	//不让选择周六，周日   
                //disabledDaysText: "周末要休息",   
                invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                anchor: '90%',
                vtype: 'daterange',
                startDateField: 'date_begin'
            });
                
            var airports = new Ext.ux.ItemSelector({
                xtype: "itemselector",
                name: "airports",
                imagePath: "/images/multi_select",
                drawUpIcon: false,
                drawDownIcon: false,
                drawLeftIcon: true,
                drawRightIcon: true,
                drawTopIcon: false,
                drawBotIcon: false,
                fieldLabel: "<span class='red'>*</span>目的地选择",
                dataFields: ["code", "desc"],
                fromData: <%=@airports_arraystr%>,
                toData: <%=@airports_selected_arraystr%>,
                msWidth: 180,
                msHeight: 150,
                valueField: "code",
                displayField: "desc",
                //imagePath:"ext-ux/multiselect",
                //switchToFrom:true,
                toLegend: "已经选择的城市",
                fromLegend: "可选城市"
            })   
            var positions = new Ext.ux.ItemSelector({
                xtype: "itemselector",
                name: "position",
                imagePath: "/images/multi_select",
                drawUpIcon: false,
                drawDownIcon: false,
                drawLeftIcon: true,
                drawRightIcon: true,
                drawTopIcon: false,
                drawBotIcon: false,
                fieldLabel: "<span class='red'>*</span>舱位选择",
                dataFields: ["code", "desc"],
                //fromData: [[123, "One Hundred Twenty Three"], ["1", "One"], ["2", "Two"], ["3", "Three"], ["4", "Four"], ["5", "Five"], ["6", "Six"], ["7", "Seven"], ["8", "Eight"], ["9", "Nine"]],
                fromData: <%=@positionStr%>,
                toData: <%=@positionSelected%>,
                msWidth: 180,
                msHeight: 150,
                valueField: "code",
                displayField: "desc",
                //imagePath:"ext-ux/multiselect",
                //switchToFrom:true,
                toLegend: "已经选择的舱位",
                fromLegend: "可选舱位"
            })
                
            policyForm = new Ext.form.FormPanel({
                labelWidth: 80,
                width: 550,
                frame: true,
                labelAlign: 'right',
                url: '/admin/savePolicy?id=<%=@id%>',
                reader: new Ext.data.JsonReader({
                    root: 'root'
                }, [{
                        name: 'id'
                    }, {
                        name: 'airports_to_desc'
                    }, {
                        name: 'flights'
                    }, {
                        name: 'date_begin',type: 'date',
                        dateFormat: 'Y/m/d'
                    }, {
                        name: 'date_end',type: 'date',
                        dateFormat: 'Y/m/d'
                    }, {
                        name: 'position'
                    }, {
                        name: 'rake_off'
                    }, {
                        name: 'trip_type'
                    }]),
                items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [airways]
                            }, {
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [airportFrom]
                            }]
                    },airports,positions,flights,  {
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [rakeOff]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [single]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [twice]
                            }]
                    },{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [dateBegin]
                            }, {
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [dateEnd]
                            }]
                    }],
                buttons: [{
                        text: '保存',
                        handler: function(){
                            // check form value 
                            this.disable();
                            if (policyForm.form.isValid()) {
                                policyForm.form.submit({
                                    //url: '/admin/addPolicy',
                                    //params: policyForm.form.getValues(true),
                                    method: 'GET',
                                    success: function(result, response){
                                        if (response.result.info == "政策编辑成功") {
                                            Ext.MessageBox.alert('提示', response.result.info);
                                            //editPolicyWindow.destroy();
                                            editPolicyWindow.hide();
                                            policyDS.load({
                                                params: {
                                                    start: 0,
                                                    limit: 10
                                                }
                                            });
                                        }
                                        else {
                                            Ext.MessageBox.alert('错误消息', response.result.info);
                                        }
                                    },
                                    failure: function(result, request){
                                        Ext.MessageBox.alert('错误消息', '编辑政策失败!');
                                    }
                                });
                            }
                            else {
                                Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                            }
                        }
                    }, {
                        text: '取消',
                        handler: function(){
                            //editPolicyWindow.destroy();
                            editPolicyWindow.hide();
                        }
                    }]
            });
                
            policyForm.form.load({
                url: "/admin/getPolicyByID?id=<%=@id%>",
                waitMsg: '正在载入数据...',
                success: function(form, action){
                    //Ext.MessageBox.alert('提示信息', '信息加载成功！');
                    airways.setRawValue(form.reader.jsonData.root[0].airways.airways_name);
                    airportFrom.setRawValue(form.reader.jsonData.root[0].airport_from.airport_name);
                },
                failure: function(form, action){
                    Ext.MessageBox.alert('提示信息', '政策编辑信息加载失败');
                }
            });
            policyForm.render("policy_form");
        });
    </script>
  </body>
</html>
